package pers.lan.array;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/22 2:55 PM
 */
public class LC_973 {

    public static void main(String[] args) {
        System.out.println(Arrays.deepToString(new LC_973().kClosest(new int[][]{
                {1, 3}, {-2, 2}
        }, 1)));
    }

    public int[][] kClosest(int[][] points, int K) {
        return Arrays.stream(points)
                .sorted((o1, o2) -> o1[0] * o1[0] + o1[1] * o1[1] - o2[0] * o2[0] - o2[1] * o2[1])
                .collect(Collectors.toList())
                .subList(0, K)
                .toArray(new int[][]{});
    }
}
